package com.zany.net.convert;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.zany.net.dto.Header;
import com.zany.net.dto.request.QueryMoneyReq;
import com.zany.net.dto.request.RequestEntity;
import com.zany.net.service.ConvertService;

public class QueryMoneyReqConvert implements ConvertService {

    @Override
    public RequestEntity convert(JsonObject jsonObject) {
        JsonElement bodyElement = jsonObject.get(BODY);
        JsonElement headerElement = jsonObject.get(HEADER);
        JsonObject asJsonObject = headerElement.getAsJsonObject();
        String msgcd = asJsonObject.get(MSGCD).getAsString();
        String snddt = asJsonObject.get("snddt").getAsString();
        String sndappcd = asJsonObject.get("sndappcd").getAsString();
        String seqnb = asJsonObject.get("seqnb").getAsString();
        JsonObject asJsonBodyObject = bodyElement.getAsJsonObject();
        RequestEntity requestEntity = new RequestEntity();
        Header header = new Header();
        header.setMsgcd(msgcd);
        header.setSnddt(snddt);
        header.setSndappcd(sndappcd);
        header.setSeqnb(seqnb);
        QueryMoneyReq requestBody = new QueryMoneyReq();
        String org_code = asJsonBodyObject.get("org_code").getAsString();
        String query_param = asJsonBodyObject.getAsJsonObject("query_param").getAsString();
        String query_type = asJsonBodyObject.getAsJsonObject("query_type").getAsString();
        requestBody.setOrgCode(org_code);
        requestBody.setQueryParam(query_param);
        requestBody.setQueryType(query_type);
        requestEntity.setHeader(header);
        requestEntity.setBody(requestBody);
        return requestEntity;
    }
}
